/**
 * Description:
 * User: Vijay <1937832819@qq.com>
 * Date: 2020/08/19
 * Time: 10:33
 */

package models

import "github.com/astaxie/beego/orm"

type Article struct {
	Id          int
	CategoryId  int
	Slug        string
	Title       string
	Author      string
	Content     string
	Markdown    string
	Description string
	Keywords    string
	Cover       string
	IsTop       int
	Click       int
	Status      int
	CreatedAt   string
	UpdatedAt   string
	DeletedAt   string
}

func (a *Article) TableName() string {
	return TableName("articles")
}

/**
置顶文章
*/
func (a *Article) topArticle() ([]*Article) {
	list := make([]*Article, 0)
	o := orm.NewOrm()
	qs := o.QueryTable(a.TableName()) // 返回 QuerySeter
	qs.Filter("is_top", 1)
	qs.Filter("status", 1)
	qs.Limit(3)
	qs.OrderBy("-updated_at")
	qs.All(&list)
	return list
}
